//
//  PSEvaluatorTests.m
//  PrefCore
//
//  Created by Sergey on 5/30/14.
//  Copyright (c) 2014 Play-on-smart. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "PSEvaluator.h"
@interface PSEvaluatorTests : XCTestCase

@end

@implementation PSEvaluatorTests

- (void)testCreateMisere {
    XCTAssertNotNil([PSEvaluator evaluatorForType:kEvaluatorMisere]);
}

- (void)testCreatePassing {
    XCTAssertNotNil([PSEvaluator evaluatorForType:kEvaluatorPassing]);
}

- (void)testCreateTricking {
    XCTAssertNotNil([PSEvaluator evaluatorForType:kEvaluatorTricking]);
}

-(void)testGoThroughCards {
    PSEvaluator *minEvals[] = {
        [PSEvaluator evaluatorForType:kEvaluatorMisere]
    ,   [PSEvaluator evaluatorForType:kEvaluatorPassing]
    };
    PSCard *cards[] = {
        [PSCard cardWithSuit:kSuitSpades andRank:kRankKing]
    ,   [PSCard cardWithSuit:kSuitSpades andRank:kRankTen]
    ,   [PSCard cardWithSuit:kSuitSpades andRank:kRankEight]
    ,   [PSCard cardWithSuit:kSuitSpades andRank:kRankSeven]
    ,   [PSCard cardWithSuit:kSuitClubs andRank:kRankQueen]
    ,   [PSCard cardWithSuit:kSuitDiamonds andRank:kRankAce]
    ,   [PSCard cardWithSuit:kSuitHearts andRank:kRankKing]
    };
    PSHandHash cand = 0;
    for (int i = 0 ; i != 7 ; i++) {
        cand = PSHandAddCard(cand, cards[i]);
    }
    int k;
    for (int i = 0 ; i != 2 ; i++) {
        PSEvaluator *e = minEvals[i];
        PSCardHash c = [e startWithCandidates:cand];
        k = 0;
        while (c != 0) {
            XCTAssertEqual(cards[k++].hash32, c);
            c = [e nextWithCandidates:cand andCurrent:c];
        }
    }
    PSEvaluator *e = [PSEvaluator evaluatorForType:kEvaluatorTricking];
    PSCardHash c = [e startWithCandidates:cand];
    while (c != 0) {
        XCTAssertEqual(cards[--k].hash32, c);
        c = [e nextWithCandidates:cand andCurrent:c];
    }
}

@end
